package com.note.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.note.common.domain.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 评论Mapper
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    /**
     * 分页查询笔记评论
     * 
     * @param page 分页参数
     * @param noteId 笔记ID
     * @return 分页结果
     */
    @Select("SELECT * FROM comment WHERE note_id = #{noteId} AND deleted = 0 ORDER BY created_at DESC")
    IPage<Comment> selectPageByNoteId(Page<Comment> page, @Param("noteId") Long noteId);
    
    /**
     * 查询用户所有评论
     * 
     * @param page 分页参数
     * @param userId 用户ID
     * @return 分页结果
     */
    @Select("SELECT * FROM comment WHERE user_id = #{userId} AND deleted = 0 ORDER BY created_at DESC")
    IPage<Comment> selectPageByUserId(Page<Comment> page, @Param("userId") Long userId);
    
    /**
     * 查询笔记评论数量
     * 
     * @param noteId 笔记ID
     * @return 评论数量
     */
    @Select("SELECT COUNT(*) FROM comment WHERE note_id = #{noteId} AND deleted = 0")
    int countCommentsByNoteId(@Param("noteId") Long noteId);
    
    /**
     * 查询用户评论数量
     * 
     * @param userId 用户ID
     * @return 评论数量
     */
    @Select("SELECT COUNT(*) FROM comment WHERE user_id = #{userId} AND deleted = 0")
    int countCommentsByUserId(@Param("userId") Long userId);
} 